<?php /*a:1:{s:94:"D:\p\phpstudy_pro\WWW\zhengmaotong\public/themes/admin_simpleboot3/project\goods\set_attr.html";i:1718698309;}*/ ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0">
    <meta http-equiv="X-UA-Compatiable" content="ie=edge">
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <el-form :inline="true" :model="form" >

        <div v-for="(item,index) in form">
            <!--            下拉框属性选择-->
            <el-form-item label="商品属性">
                <el-select  placeholder="商品属性" v-model="item.attr">
                    <el-option v-for="s in selectOption" :label="s.attr" :value="s.id" ></el-option>
                </el-select>
            </el-form-item>
            <!--            属性-->
            <el-form-item :label="'商品属性' + (index + 1)">
                <el-input v-model="item.attr_value" placeholder="请输入商品属性"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="danger" @click="removeFormItem(index)">移除</el-button>
            </el-form-item>
        </div>

    </el-form>
    <div>
        <el-button type="default" @click="addFormItem">增加属性</el-button>
    </div>
    <div style="margin-top:20px">
        <el-button type="default" @click="submitFormItem">保存</el-button>
    </div>
</div>

<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
    v = new Vue({
        el:'#app',
        data:{
            goods_id:"<?php echo $goods_id; ?>",
            form:[
                {attr:'',attr_value:''},
            ],
            selectOption:[]
        },
        methods:{
            //添加表单项
            addFormItem(){
                this.form.push({attr:'',attr_value:''},)
            },
            //移除表单项
            removeFormItem(index)
            {
                this.form.splice(index,1)
            },
            //提交表单项
            submitFormItem(){
                $.ajax({
                    url:"<?php echo url('Goods/sentAttrIndex'); ?>",
                    type:'POST',
                    data:{
                        goods_id:this.goods_id,
                        attr:this.form
                    },
                    success(res){

                    },
                    error(res){
                        alert('请求失败')
                    }
                })
            }
        },
        created(){
            $.ajax({
                url:"<?php echo url('Goods/getGoodsAttr'); ?>",
                type:"POST",
                data:{
                    goods_id:this.goods_id
                },
                success(res) {
                    v.selectOption = res.data
                    console.log(v.selectOption)
                },
                error(res){
                    alert('失败')
                }
            })
        }
    })
</script>
</body>
</html>